home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-10-15 | 6.8 KB | 286 lines | [TEXT/CWIE] |
- // ===========================================================================
- // CTridentApp.cp ©1993 Metrowerks Inc. All rights reserved.
- // ===========================================================================
-
- #include "CTridentApp.h"
- #include "TridentAESuite.h"
- #include "CTridentCmds.h"
- #include "CTridentView.h"
- #include "CTridentwhoView.h"
- #include "CTridentuptimeView.h"
-
- #include <LFile.h>
- #include <LListener.h>
- #include <LView.h>
- #include <LWindow.h>
- #include <LTable.h>
- #include <LTextEdit.h>
- #include <LPrintout.h>
- #include <LPlaceHolder.h>
- #include <LGrowZone.h>
- #include <UMemoryMgr.h>
- #include <LUndoer.h>
- #include <URegistrar.h>
- #include <UReanimator.h>
- #include <UPrintingMgr.h>
- #include <UDesktop.h>
- #include <UDrawingState.h>
- #include <PP_Messages.h>
- #include <PPobClasses.h>
- #include <Sound.h>
-
- #ifndef __STANDARDFILE__
- #include <StandardFile.h>
- #endif
-
- #define cmd_whoView 900
- #define cmd_uptimeView 1000
- #define cConfig10 421;
- #define cConfig30 422;
- #define cConfig60 423;
- #define cConfig600 424;
- #define cConfig3600 425;
-
- class CTridentView;
- class CTridentwhoView;
- class CTridentuptimeView;
- // ===========================================================================
- // • Main Program
- // ===========================================================================
-
- void main(void)
- {
- SetDebugThrow_(debugAction_Alert);
- SetDebugSignal_(debugAction_Alert);
-
- InitializeHeap(3);
- UQDGlobals::InitializeToolbox(&qd);
- new LGrowZone(20000);
-
- CTridentApp theApp;
- theApp.Run();
- }
-
-
- // ---------------------------------------------------------------------------
- // • CTridentApp
- // ---------------------------------------------------------------------------
- // Default constructor
-
- CTridentApp::CTridentApp()
- {
- fDocumentCount = 0;
- RegisterAllPPClasses();
- URegistrar::RegisterClass('wind', (ClassCreatorFunc) CTridentWindow::CreateTridentWindowStream);
- URegistrar::RegisterClass('vwvw', (ClassCreatorFunc) CTridentView::CreateTridentViewStream);
- URegistrar::RegisterClass('vwaa', (ClassCreatorFunc) CTridentwhoView::CreateTridentViewStreamA);
- URegistrar::RegisterClass('vwbb', (ClassCreatorFunc) CTridentuptimeView::CreateTridentViewStreamB);
- }
-
-
- // ---------------------------------------------------------------------------
- // • ~CTridentApp
- // ---------------------------------------------------------------------------
- // Destructor
- //
-
- CTridentApp::~CTridentApp()
- {
-
- }
-
- void
- CTridentApp::HandleNewConnection(ResIDT theWinID)
- {
- CTridentWindow* myWindow = (CTridentWindow*) LWindow::CreateWindow(theWinID, this);
- myWindow->SetPortRefNum(fDocumentCount++);
-
- myWindowList.InsertItemsAt(1, arrayIndex_Last, &myWindow); //has to be here early to handle apple events
- ((CTridentWindow*)myWindow)->Connect();
-
- if (!myWindow->IsConnected())
- {
- myWindowList.Remove(&myWindow);
- delete myWindow;
- return; //command handled
- }
- CTridentView* myListBox = (CTridentView*) myWindow->myView; //gets set in send version if "S"uccess
-
- if (myListBox)
- {
- ListHandle theList = myListBox->GetMacListH();
- LAddColumn(1,0, theList);
- }
-
- ((CTridentWindow*)myWindow)->SendInterval(30);
- ((CTridentWindow*)myWindow)->SendHeart();
-
- }
-
- Boolean
- CTridentApp::ObeyCommand(
- CommandT inCommand,
- void *ioParam)
- {
- Boolean cmdHandled = true;
- switch (inCommand) {
-
- case cmd_whoView:
- this->HandleNewConnection(cmd_whoView);
- cmdHandled = TRUE;
- break;
-
- case cmd_uptimeView:
- { // EXAMPLE, create a new window
- this->HandleNewConnection(cmd_uptimeView);
- cmdHandled = TRUE;
- break;
- }
- default:
- cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
- break;
- }
-
- return cmdHandled;
- }
-
-
-
- void
- CTridentApp::FindCommandStatus(
- CommandT inCommand,
- Boolean &outEnabled,
- Boolean &outUsesMark,
- Char16 &outMark,
- Str255 outName)
- {
-
- switch (inCommand) {
-
- // Return menu item status according to command messages.
- // Any that you don't handle will be passed to LApplication
- case 421:
- case 422:
- case 423:
- case 424:
- case 425:
- if (myWindowList.GetCount() > 0)
- {
- CTridentWindow *theFrontWindow = NULL;
-
- LListIterator iterator(myWindowList, iterate_FromStart);
- CTridentWindow *theSub;
- while (iterator.Next(&theSub)) {
- if (UDesktop::WindowIsSelected(theSub))
- {
- theFrontWindow = theSub;
- continue;
- }
- }
-
- if (theFrontWindow != NULL)
- theFrontWindow->FindCommandStatus(inCommand, outEnabled, outUsesMark, outMark, outName);
-
- }
- break;
-
- case cmd_whoView: // EXAMPLE
- outEnabled = TRUE; // enable the New command
- break;
-
- case cmd_uptimeView: // EXAMPLE
- outEnabled = TRUE; // enable the New command
- break; default:
- LApplication::FindCommandStatus(inCommand, outEnabled,
- outUsesMark, outMark, outName);
- break;
- }
- }
-
- void
- CTridentApp::HandleAppleEvent(
- const AppleEvent &inAppleEvent,
- AppleEvent &outAEReply,
- AEDesc &outResult,
- long inAENumber)
- {
- OSErr err;
- // LStr255 theText = "this is a test";
- // char string[1024];
- DescType actualCode;
- long actualSize;
- CTridentWindow* theWindow;
- long theConnectionNumber;
- // LListBox* myListBox;
-
- switch (inAENumber) {
-
- case ae_Close:
- SysBeep(3);
- break;
- case kAEJavMsg:
- case keyMessageCode:
- case 407:
- case 408:
- err = ::AEGetParamPtr(&inAppleEvent, keySessionID, typeLongInteger, &actualCode, (Ptr) & theConnectionNumber, sizeof(theConnectionNumber), &actualSize);
- theWindow = this->LocateWindowBySession(theConnectionNumber);
- if (theWindow!= NULL)
- theWindow->HandleAppleEvent(inAppleEvent, outAEReply, outResult, inAENumber);
- break;
-
- default:
-
- inherited::HandleAppleEvent(inAppleEvent, outAEReply,
- outResult, inAENumber);
- break;
- }
- }
-
- CTridentWindow* CTridentApp::LocateWindowBySession(short theSessionID)
- {
- CTridentWindow* theWindow = NULL;
-
- LListIterator iterator(myWindowList, iterate_FromStart);
- CTridentWindow *theSub;
- while (iterator.Next(&theSub)) {
- if (theSessionID == theSub->fPortRefNum)
- theWindow = theSub;
- if (theWindow != nil) break;
- }
- return theWindow;
- }
-
- CTridentWindow* CTridentApp::LocateWindowByPaneIDT(PaneIDT thePaneIDT)
- {
- CTridentWindow* theWindow = NULL;
-
- LListIterator iterator(myWindowList, iterate_FromStart);
- CTridentWindow *theSub;
- while (iterator.Next(&theSub)) {
- if (thePaneIDT == theSub->GetPaneID())
- theWindow = theSub;
- if (theWindow != nil) break;
- }
- return theWindow;
- }
-
- void
- CTridentApp::CloseWindow(PaneIDT thePane)
- {
- CTridentWindow* theWindow = (CTridentWindow*) this->LocateWindowByPaneIDT(thePane);
- if (theWindow == NULL)
- return;
-
- theWindow->SendQuit();
-
- switch(thePane)
- {
- case cmd_whoView: //Bwindow ..regular javelin
- myWindowList.Remove(&theWindow);
- break;
- case cmd_uptimeView: //Awindow ..something neat and yet mysterious
- myWindowList.Remove(&theWindow);
- break;
- }
- //delete theWindow;
- }